const _my = require("../../__antmove/api/index.js")(my);
const wx = _my;
let disp = require("../../utils/broadcast");
Page({
    data: {
        username: {
            your: ""
        }
    },
    // options = 系统传入的 url 参数
    onLoad(options) {
        let me = this;
        let username = (options && JSON.parse(options.username)) || {};
        console.log("username *****", username);
        this.setData({
            username: username
        });
        let title = username.your
        if (title === 'user_bot') {
          title += ' (ai助手 非真人)'
        }
        wx.setNavigationBarTitle({
            title
        });
        disp.on("em.megList.refresh", function() {
            const pages = getCurrentPages();
            const currentPage = pages[pages.length - 1];
            if (currentPage.route == "pages/chatroom/chatroom") {
                me.onLoad();
            }
        });
        if (username.action == "join") {
            console.log("username", username);
            this.selectComponent("#chat").joinConf(username.data);
        }
        disp.on("emedia.confirmRing", function(event) {
            console.log("event", event);
            me.selectComponent("#chat").joinConf();
        });
        if("user_bot" === username.your) {
          // 弹窗
          my.confirm({
            title: '温馨提示',
            content: '/list   查看当前系统支持的模型 \n /use 5    使用模型5 \n /ask 内容  向ai提问',
          });
        };
    },
    onUnload() {
        disp.fire("em.chatroom.leave");
    },
    onPullDownRefresh: function() {
        wx.showNavigationBarLoading();
        this.selectComponent("#chat").getMore();
        // 停止下拉动作
        wx.hideNavigationBarLoading();
        wx.stopPullDownRefresh();
    }
});
